<?php
class Shop_Model_Order extends Zend_Db_Table
 {
       	protected $_name="orders";
       	protected $_primary = 'id';
        
 		public function insertOrder($arrParam = null, $option = null)
	  	{	
	  		$product = new Shop_Model_Product();			
			$product_item = $product->getItemById($arrParam['productid']);
	  		
	  		$row = $this->fetchNew();		  	
			$row->customerid       =$arrParam['customerid'];						
			$row->productid       =$arrParam['productid'];
			$row->shopid       =$product_item['shopid'];
			$row->createdate       =date('Y-m-d h:i:s',time());
			$row->lastupdate       =date('Y-m-d h:i:s',time());
			$row->status       ="";
			$row->number       =$arrParam['number'];
			$row->payment_method       =$arrParam['payment_method'];
			$row->total_paid       =$arrParam['total_paid'];
			
		  	return $row->save();
	  	}
	  	
 		public function updateOrder($arrParam = null, $option = null)
		{
			$db = Zend_Registry::get('connectDB');	
			$where = "id = '".$arrParam['id']."'";

			$data = array();
			
			if (@$arrParam['status'] != ""){
				$data["status"]=$arrParam['status'];
			}
			
			if (@$arrParam['number'] != ""){
				$data["number"]=$arrParam['number'];
			}
			
			if (@$arrParam['payment_method'] != ""){
				$data["payment_method"]=$arrParam['payment_method'];
			}
			
			if (@$arrParam['total_paid'] != ""){
				$data["total_paid"]=$arrParam['total_paid'];
			}
									
			$db->update("orders", $data, $where);
		}
	  	
 		public function listItemProductCustomer($arrParam = null, $option = null){
			
			$db = Zend_Registry::get('connectDB');
					
	  		$sql = "select orders.id as ordersid,customer.id as customerid,product.id as productid,product.shopid as shopid,orders.createdate,orders.status,orders.payment_method,orders.total_paid,orders.number,customer.displayname,customer.email,customer.phone,customer.address,customer.district,customer.province,product.detail,product.image,product.stock,product.sku from orders inner join customer on orders.customerid = customer.id inner join product on product.id = orders.productid where product.shopid = '".$arrParam['shopid']."' order by orders.status";
	  		$result = $db->fetchAll($sql);
			
	  		return $result;
	  	} 
        
 }